<template>
  <view>
    <!-- 花积分正常支付 -->
    <hlhy v-if="isHjfShop"></hlhy>
    <!-- 鑫复来正常支付 -->
    <xlf v-if="isflqShop"></xlf>
    <!-- 黑银正常支付 -->
    <HY v-if="isHYShop"></HY>
    <!-- 花积分无感支付 -->
    <hlhyPay v-if="isHjfQRShop"></hlhyPay>
    <!-- 长来无感支付 -->
    <clwgPay v-if="isClShop"></clwgPay>
    <!-- 长来正常支付 -->
    <clPay v-if="isClZcShop"></clPay>
  </view>
</template>
<script setup lang="ts">
import { computed, reactive, ref, watch, nextTick } from 'vue'
import { onLoad, onShow, onReady } from '@dcloudio/uni-app'
//存储
import { storeToRefs } from 'pinia'
import { useConfigStore, useUserStore } from '@/store'
//api
import { enumAll, moneyApi, orderApi, productApi } from '@/api'
//  组件
import hyDownloadTips from '@/components/hy-download-tips/index.vue'
import HY from './hy.vue'
import hlhy from './hlhy.vue'
import xlf from './xlf.vue'
import hlhyPay from './hlhyPay.vue'
import clwgPay from './clwgPay.vue'
import clPay from './clPay.vue'
//工具
import { generateAlipayAuthUrl } from '@/utils/common'
import debounce from 'lodash/debounce'
//图片
import moneyIcon from '@/static/hlhy/money2.png'
import shopIcon1 from '@/static/hlhy/shopIcon1.png'

//初始数据
const configStore = useConfigStore()
const userStore = useUserStore()
const { enterByStoreQrcode, isWeChatBrowser, isAlipayClient } =
  storeToRefs(configStore)
const { accessToken, useShareCode } = storeToRefs(userStore)
const info = reactive({
  name: '',
  shopId: '',
  shopMoneyRules: []
})
const money = ref()
const orderData = ref({
  remark: ''
})
const productSku = ref()
const flqScore = ref()
const moneyRuleId = ref(null)

const isHjfShop = ref(false) // 是否花积分
const isHjfQRShop = ref(false) // 是否花积分无感支付
const qrcode = ref(false) // 是否无感支付的标识
const isflqShop = ref(false) // 是否复来券
const isHYShop = ref(false) // 是否黑银
const isClShop = ref(false) //是否长来无感支付
const isClZcShop = ref(false) //是否是长来正常支付
const shopType = ref('') //店铺类型
async function getShopType() {
  const { data, code } = await productApi.getShopType({
    shopId: info.shopId
  })
  console.log(data, 'data店铺')
  if (code == 200) {
    shopType.value = data
    switch (Number(data)) {
      case 1:
        if (qrcode.value) {
          isHjfQRShop.value = true
        } else {
          isHjfShop.value = true
        }
        break
      case 4:
        isflqShop.value = true
        break
      case 6:
        if (qrcode.value) {
          isClShop.value = true
        } else {
          isClZcShop.value = true
        }
        break
      default:
        isHYShop.value = true
        break
    }
  }
}

const inptDisabled = ref(false)
const btnColor = ref('2979ff')
onLoad(async (option) => {
  if (option?.qrcode) {
    qrcode.value = true //确认无感支付
  }
  if (option) {
    const { shopId } = option
    info.shopId = shopId
    getShopType()
    if (option.moneyRuleId) {
      moneyRuleId.value = option.moneyRuleId
    }
  }
  // if (!userStore.hasLogin && !option?.hasOwnProperty('qrcode')) {
  //   uni.navigateTo({
  //     url: '/pages/login/index'
  //   })
  // }
  // if (option?.money) {
  //   money.value = option.money
  //   inptDisabled.value = true
  // }
  // if (option?.color) {
  //   btnColor.value = option.color
  // }
})
</script>

<style lang="scss" scoped></style>
